package com.example.yiwei.crm.json;

import com.example.yiwei.crm.entity.scheduleEntity;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by DHN on 2017/5/2.
 */

public class VisitJson {
    public static List<scheduleEntity> jsonVisitMessage(String result){
        scheduleEntity scheduleEntity;
        List<com.example.yiwei.crm.entity.scheduleEntity> list;
        try {
            JSONObject object=new JSONObject(result);
                list=new ArrayList<>();
                JSONArray array=object.getJSONArray("list");
                for (int i=0;i<array.length();i++){
                    JSONObject json=array.getJSONObject(i);
                    scheduleEntity=new scheduleEntity();
                    if (json.has("KXA01")){
                        scheduleEntity.setDocking_id(json.getInt("KXA01"));
                    }
                    if (json.has("KPA01")){
                        scheduleEntity.setVisit_id(json.getInt("KPA01"));
                    }
                    if (json.has("KPA02")){
                        scheduleEntity.setSchedule_theme(json.getString("KPA02"));
                    }
                    if (json.has("KPA11")){
                        scheduleEntity.setManager_name(json.getString("KPA11"));
                    }
                    if (json.has("AKK01")){
                        scheduleEntity.setTask_state_id(json.getInt("AKK01"));
                    }
                    if (json.has("AKJ01")){
                        scheduleEntity.setPriority_id(json.getInt("AKJ01"));
                    }
                    if (json.has("AKJ03")){
                        scheduleEntity.setPriority(json.getString("AKJ03"));
                    }
                    if (json.has("AKK03")){
                        scheduleEntity.setTask_state(json.getString("AKK03"));
                    }
                    if (json.has("KPA06L")){
                        scheduleEntity.setVisit_time(json.getString("KPA06L"));
                    }
                    if (json.has("KPA09")){
                        scheduleEntity.setVisit_gift(json.getString("KPA09"));
                    }
                    if (json.has("KPA10")){
                        scheduleEntity.setGift_value(json.getString("KPA10"));
                    }
                    if (json.has("CID03")){
                        scheduleEntity.setCurrent_create_user_name(json.getString("CID03"));
                    }
                    if (json.has("KPA14")){
                        scheduleEntity.setDirector_required(json.getString("KPA14"));
                    }
                    if (json.has("CTS01L")){
                        scheduleEntity.setCreate_time(json.getString("CTS01L"));
                    }
                    if (json.has("REK01")){
                        scheduleEntity.setAdditional_remarks(json.getString("REK01"));
                    }
                    list.add(scheduleEntity);

                }
                return list;

        } catch (JSONException e) {
            e.printStackTrace();
        }
        return null;
    }
}
